<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class DawnOssSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 定义一些示例文件类型
        $imageTypes = ['jpg', 'png', 'gif'];
        $docTypes = ['pdf', 'doc', 'docx'];
        $otherTypes = ['zip', 'txt'];

        // 创建50条测试数据
        for ($i = 0; $i < 50; $i++) {
            // 随机选择文件类型
            $fileCategory = rand(1, 3);
            switch ($fileCategory) {
                case 1: // 图片
                    $fileType = $imageTypes[array_rand($imageTypes)];
                    $mimeType = 'image/' . ($fileType === 'jpg' ? 'jpeg' : $fileType);
                    break;
                case 2: // 文档
                    $fileType = $docTypes[array_rand($docTypes)];
                    $mimeType = $fileType === 'pdf' ? 'application/pdf' : 'application/msword';
                    break;
                default: // 其他
                    $fileType = $otherTypes[array_rand($otherTypes)];
                    $mimeType = $fileType === 'zip' ? 'application/zip' : 'text/plain';
            }

            // 生成随机文件名
            $fileName = Str::random(10) . '.' . $fileType;
            
            // 生成存储路径
            $userId = rand(1, 5); // 假设有5个用户
            $month = str_pad(rand(1, 12), 2, '0', STR_PAD_LEFT);
            $filePath = "uploads/{$userId}/2024{$month}/{$fileName}";

            DB::table('dawn_osses')->insert([
                'user_id' => $userId,
                'file_name' => "测试文件_{$i}_{$fileName}",
                'file_path' => $filePath,
                'file_type' => $fileType,
                'file_size' => rand(1000, 10000000), // 1KB到10MB之间
                'storage_type' => 'local',
                'mime_type' => $mimeType,
                'file_hash' => md5(Str::random(16)),
                'status' => rand(0, 10) > 1 ? 1 : 0, // 90%的概率是正常状态
                'created_at' => now()->subDays(rand(0, 30)), // 最近30天内的随机时间
                'updated_at' => now()->subDays(rand(0, 30))
            ]);
        }
    }
}
